****************************************************************************
* Table A.6: Relationship between relative age at election t0 and party preferences
****************************************************************************

use  "Data_temp/polit_involv.dta", clear




gen votefor_labour=(vote3==2) if vote3>0 & vote3<. & vote3!=96
gen votefor_tories=(vote3==1) if vote3>0 & vote3<. & vote3!=96
gen votefor_libdem=(vote3==3) if vote3>0 & vote3<. & vote3!=96
gen votefor_other=(vote3!=1 & vote3!=2 & vote3!=3  & vote3!=95) if vote3>0 & vote3<. & vote3!=96



global votefor_labour	 \hline  \\ \multicolumn{4}{l}{Would vote for Labour} \\ \cmidrule{1-1}
global votefor_tories	 \hline  \\ \multicolumn{4}{l}{Would vote for Conservatives} \\ \cmidrule{1-1}
global votefor_libdem	 \hline  \\ \multicolumn{4}{l}{Would vote for Liberal Democrats} \\ \cmidrule{1-1}
global votefor_other	 \hline  \\ \multicolumn{4}{l}{Would vote for other party} \\ \cmidrule{1-1}


cap erase "Tables/a_tb6.tex"

estimates clear
foreach var of varlist votefor_labour-votefor_other { 

			
		* before first election		
		cap drop dummy*
		quiet tab year if `var'<. & inrange(age100,-24,24), gen(dummy)
			drop dummy1
		
		rdrobust `var' age100 if age100!=0  , p(1) h(24)  covs(dummy*)
			est sto mx
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)		
				
		* first year		
		cap drop dummy*
		quiet tab year if `var'<. & inrange(age0,-24,24) & rel_year>=0, gen(dummy)
			drop dummy1
		
		rdrobust `var' age0 if age0!=0  & rel_year>=0, p(1) h(24)  covs(dummy*)
			est sto m0
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)
			
		cap drop dummy*
		quiet tab year if `var'<. & inrange(age1,-24,24), gen(dummy)
			drop dummy1
			
		rdrobust `var' age1 if age1!=0, p(1) h(24)  covs(dummy*)
			est sto m1
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)
			
		cap drop dummy*
		quiet tab year if `var'<. & inrange(age2,-24,24), gen(dummy)
			drop dummy1
			
		rdrobust `var' age2 if age2!=0, p(1) h(24) covs(dummy*)
			est sto m2
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)
			
		cap drop dummy*
		quiet tab year if `var'<. & inrange(age3,-24,24), gen(dummy)
			drop dummy1
			
		rdrobust `var' age3 if age3!=0, p(1) h(24) covs(dummy*)
			est sto m3
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)
	
		cap drop dummy*
		quiet tab year if `var'<. & inrange(rel_age2,-24,24), gen(dummy)
			drop dummy1
			
		rdrobust `var' rel_age2 if rel_age2!=0, p(1) h(24) covs(dummy*)
			est sto m4
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)
	
		estout m* using "Tables/a_tb6.tex", ///
			style(tex) cells (b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
			starlevels( * 0.1 ** 0.05 *** 0.01)  varlabels(RD_Estimate "${`var'} RD estimate")	  ///
			stats(eff_obs, fmt(%9.0gc) labels("N"))    mlabels(none) ///
			collabels(none) eql(none) notype label append 	
	
		}
		
		
		